# encoding: utf-8
# @File  : spider_result.py
# @Author: shaoyun
# @Date  :  2025/06/03
from datetime import datetime
from typing import Dict, Any, Optional

from pydantic import BaseModel, Field, ConfigDict


class SpiderResult(BaseModel):
    """爬虫结果模型"""
    task_id: str = Field(..., description="任务ID")
    spider_id: str = Field(..., description="爬虫ID")
    success: bool = Field(..., description="执行是否成功")
    data: Dict[str, Any] = Field(default_factory=dict, description="爬虫返回的数据")
    error: Optional[str] = Field(None, description="错误信息")
    created_at: datetime = Field(default_factory=datetime.utcnow, description="结果创建时间")
    updated_at: datetime = Field(default_factory=datetime.utcnow, description="结果更新时间")

    model_config = ConfigDict(arbitrary_types_allowed=True)